package com.t.bricks.bussiness.controller.useranddepartment;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.t.bricks.bussiness.db.entity.useranddepartment.UserAndDepartment;
import com.t.bricks.bussiness.model.useranddepartment.LoginUser;
import com.t.bricks.bussiness.service.useranddepartment.UserAndDepartmentService;
import com.t.bricks.model.MsgEmity;

@RestController
@Api(value="人员与部门关联", tags={"基本系统-人员与部门关联操作接口"})
@RequestMapping("/user/and/department/")
public class UserAndDepartmentController {

	/**
	 * 人员部门业务实现类
	 */
	@Autowired
	private UserAndDepartmentService UserAndDepartmentService;
	
	/**
	 * 批量保存人员所属部门关联信息
	 * 注意:若部门信息为空则会清除所有该人员与部门的关联信息
	 * @param sUserId 人员编号
	 * @param sDepamentList 部门编号集合,以','分隔
	 * @return
	 */
	//[start]
	@ApiOperation(value="批量保存人员所属部门关联信息", notes="若部门信息为空则会清除所有该人员与部门的关联信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name="sUserId", value="人员编号", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="sDepamentList", value="部门编号集合以','分隔", dataType="String", paramType="query", required=false),
		@ApiImplicitParam(name="sMainDepamentId", value="所属部门编号", dataType="String", paramType="query", required=false)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=8001, message="人员编号参数为空"),
		@ApiResponse(code=7001, message="关联未能得到预期影响值(预期大于等于1)"),
		@ApiResponse(code=7002, message="操作关联时发生异常"),
		@ApiResponse(code=7101, message="解除旧有关系链失败"),
		@ApiResponse(code=7102, message="操作数据库异常"),
		@ApiResponse(code=7999, message="关联成功")
	})
	//[end]
	@RequestMapping(method={RequestMethod.POST}, value="/save")
	public MsgEmity save(String sUserId, String sDepamentList, String sMainDepamentId) {
		return UserAndDepartmentService.save(sUserId, sDepamentList, sMainDepamentId);
	}
	
	/**
	 * 根据人员编号取人员与部门关联信息
	 * @param sUserId 人员编号
	 * @return
	 */
	//[start]
	@ApiOperation(value="根据人员编号取人员与部门关联信息", response=UserAndDepartment.class)
	@ApiImplicitParams({
		@ApiImplicitParam(name="sUserId", value="人员编号", dataType="String", paramType="query", required=true)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值|Json数据对象集合}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=8001, message="人员编号参数为空"),
		@ApiResponse(code=7001, message="查询操作失败"),
		@ApiResponse(code=7002, message="查询请求失败，请查看异常日志"),
		@ApiResponse(code=7003, message="7003~8998为修改时发生的其它错误")
	})
	//[end]
	@RequestMapping(method={RequestMethod.POST}, value="/find/deparment")
	public MsgEmity findBysUserId(String sUserId) {
		return UserAndDepartmentService.findBysUserId(sUserId);
	}
	
	/**
	 * 根据部门编号查询员工
	 * @param sDeparmentId
	 * @param iMainDeparment
	 * @return
	 */
	//[start]
	@ApiOperation(value="根据部门编号查询员工", response=LoginUser.class)
	@ApiImplicitParams({
		@ApiImplicitParam(name="sDeparmentId", value="部门编号", dataType="String", paramType="query", required=true),
		@ApiImplicitParam(name="iMainDeparment", value="仅限主部门", dataType="Integer", paramType="query", required=false)
	})
	@ApiResponses({
		@ApiResponse(code=200, message="{\"success\": 布尔值, \"msg\": 文字提示, \"data\": 码值|Json数据对象集合}"),
		@ApiResponse(code=400, message="错误的请求,请检查路径"),
		@ApiResponse(code=404, message="请求路径没有或页面跳转路径不对"),
		@ApiResponse(code=1000001, message="内部请求密钥错误"),
		@ApiResponse(code=1000002, message="您还没有登录或登录已超时,需要重新登录"),
		@ApiResponse(code=1000003, message="检查登录状态失败,请稍后重试！"),
		@ApiResponse(code=1000004, message="请求的操作不存在,请检查访问地址正确性，如大小写"),
		@ApiResponse(code=1000005, message="响应后在系统内部发生不可预知的错误"),
		@ApiResponse(code=1019000, message="1019000~1999999为拦截器调用方法错误"),
		@ApiResponse(code=7001, message="查询操作失败"),
		@ApiResponse(code=7002, message="查询请求失败，请查看异常日志"),
		@ApiResponse(code=7003, message="7003~7998、8000~8998为删除时发生的其它错误"),
		@ApiResponse(code=7999, message="查询成功")
	})
	//[end]
	@RequestMapping(method={RequestMethod.POST}, value="/find/departmentid")
	public MsgEmity findByDepartmentId(String sDeparmentId, Integer iMainDeparment) {
		return UserAndDepartmentService.findByDepartmentId(sDeparmentId, iMainDeparment);
	}
	
}
